﻿using System;
using Newtonsoft.Json.Serialization;

namespace TypeScriptJson.Generator
{
	public class PrimitiveTypeMapping: TypeMapping
	{
		public JsonPrimitiveContract Contract { get; private set; }

		public override bool IsGenerateDeclaration
		{
			get { return false; }
		}

		public override string GetTypeNameInternal()
		{
			switch (Type.GetTypeCode(Contract.CreatedType))
			{
				case TypeCode.String:
				case TypeCode.Char:
				case TypeCode.DateTime:		// todo: check converter for format
					return "string";
				case TypeCode.Object:
					return "any";
				case TypeCode.Boolean:
					return "bool";
				default:
					return "number";
			}
		}

		public PrimitiveTypeMapping(JsonPrimitiveContract contract) : base(contract.UnderlyingType)
		{
			Contract = contract;
		}

		public override void WriteTypeDeclaration(TypeScriptCodeWriter codeWriter, GeneratorContext context)
		{
			throw new InvalidOperationException();
		}
	}
}